package com.kolaxy;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * <p>todo</p>
 *
 * @author zhourunjin
 * @date 2020/6/8 19:51
 */
public class TCPServer {

    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(9999);

        while (true) {
            Socket socket = ss.accept();

            InputStream inputStream = socket.getInputStream();

            byte[] b = new byte[10];

            inputStream.read(b);

            String hostAddress = socket.getInetAddress().getHostAddress();
            System.out.println(hostAddress+new String(b));

            OutputStream outputStream = socket.getOutputStream();

            outputStream.write("no way".getBytes());

            socket.close();
        }
    }
}
